/* poporcb5.p - PURCHASE ORDER RECEIPT UPDATE MRP & TRANS HIST                */
/* Copyright 1986 QAD Inc. All rights reserved.                               */
/* $Id:: poporcb5.p 64242 2015-12-28 03:26:34Z kbh                         $: */
/* REVISION: 7.4     LAST MODIFIED: 11/22/93    BY: tjs *H082*                */
/* REVISION: 7.4     LAST MODIFIED: 06/06/95    BY: rxm *G0NW*                */
/* REVISION: 7.4     LAST MODIFIED: 07/19/95    BY: rxm *G0QG*                */
/* REVISION: 8.6E    LAST MODIFIED: 02/23/98    BY: *L007* A. Rahane          */
/* REVISION: 8.6E    LAST MODIFIED: 10/04/98    BY: *J314* Alfred Tan         */
/* REVISION: 9.0     LAST MODIFIED: 04/16/99    BY: *J2DG* Reetu Kapoor       */
/* REVISION: 9.1     LAST MODIFIED: 08/13/00    BY: *N0KQ* Mark Brown         */
/* REVISION: 9.1     LAST MODIFIED: 11/08/00    BY: *N0TN* Jean Miller        */
/* REVISION: 9.1     LAST MODIFIED: 01/14/01    BY: *L15N* Rajesh Kini        */
/* Revision: 1.16    BY: Paul Donnelly (SB) DATE: 06/28/03 ECO: *Q00J*        */
/* Revision: 1.17    BY: Changlin Zeng      DATE: 04/26/06 ECO: *R045*        */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.10     BY: Sanat Paul        DATE: 09/16/07  ECO: *P657*       */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*-Revision end---------------------------------------------------------------*/
 
/* REPLACED FIND STATEMENTS WITH FOR FIRST FOR ORACLE PERFORMANCE             */
 
/*!
THE VALUES CONTAINED IN pod_det IN poporcb.p ARE THE VALUES *BEFORE* THE
RECEIPT UPDATE HAS TAKEN PLACE.  WHEN ENTERING poporcb5.p, THE pod_det RECORD
CONTAINS THE VALUES *AFTER* THE RECEIPT UPDATE HAS TAKEN PLACE.
*/
 
{us/bbi/mfdeclre.i}
{us/bbi/gplabel.i}
{us/px/pxmaint.i}
{us/px/pxphdef.i gpcmxr}
 
define shared variable po_recno as recid.
define shared variable pod_recno as recid.
define shared variable openqty like mrp_qty.
define shared variable old_status like pod_status.
define shared variable qty_ord like pod_qty_ord.
define shared variable site like pod_site.
define shared variable is-return like mfc_logical no-undo.
define variable del-yn like mfc_logical no-undo.
define variable bl_qty_chg like pod_rel_qty no-undo.
define buffer poddet for pod_det.
 
define variable use-log-acctg     as logical        no-undo.
define variable lagit             like mfc_logical  no-undo.
 
/* VALIDATE IF LOGISTICS ACCOUNTING IS TURNED ON */
{us/bbi/gprun.i ""lactrl.p"" "(output use-log-acctg)"}
 
if use-log-acctg then do:
   /* CHECK IF THIS IS LOGISTICS ACCOUNTING PO SHIPPER GIT RECEIPT PROGRAM */
   {us/bbi/gprun.i ""gpckpprg.p"" "(input 'lagitrc', output lagit)"}
   if not lagit then do:
      /* POSHIVMT IS ALSO MOVING TO TRANSIT */
      {us/bbi/gprun.i ""gpckpprg.p"" "(input 'poshivmt', output lagit)"}
   end.
end.
 
{us/in/inmrp1.i}
 
for first po_mstr
   where recid(po_mstr) = po_recno no-lock:
end. /* FOR FIRST PO_MSTR */
 
for first pod_det
   where recid(pod_det) = pod_recno no-lock:
end. /* FOR FIRST POD_DET */
 
/*DELETE IF CLOSING OR CANCELLING A LINE*/
if (pod_status = "c" or pod_status = "x" )
   and old_status <> "c"
   and old_status <> "x"
   and (pod_type = "" or pod_type = "m")
then do:
   if pod_status = "x" and pod_blanket <> "" then do:
      {us/po/pobladj.i}
   end.
 
   if pod_type = ""
   then do:
      /* MRP WORKFILE AND PART MASTER MRP FLAG */
      {us/mf/mfmrwdel.i "pod_det" pod_part pod_nbr string(pod_line) """"}
   end.
 
   run inmrp (input pod_part, input pod_site).
 
end.
 
/*ADD IF LINE IS NOT CLOSED OR CANCELLED*/
if pod_status <> "c" and pod_status <> "x" and pod_type = "" then do:
   if not is-return then do:
      {us/mf/mfpotr.i "ADD" "RECEIPT"}
   end.
 
   if pod_qty_ord >= 0 then
      openqty = max(pod_qty_ord - pod_qty_rcvd,0) * pod_um_conv.
   else
      openqty = min(pod_qty_ord - pod_qty_rcvd,0) * pod_um_conv.
 
   for first loc_mstr
      where loc_mstr.loc_domain = global_domain and  loc_site = pod_site
      and   loc_loc  = pod_loc
   no-lock:
   end. /* FOR FIRST loc_mstr */
 
   if available loc_mstr
      then
   for first is_mstr
      where is_mstr.is_domain = global_domain and  is_status =
      loc_status
   no-lock:
   end. /* FOR FIRST is_mstr */
   else do:
      for first si_mstr
         where si_mstr.si_domain = global_domain and  si_site = pod_site
      no-lock:
      end. /* FOR FIRST si_mstr */
      if available si_mstr
         then
      for first is_mstr
         where is_mstr.is_domain = global_domain and  is_status =
         si_status
      no-lock:
      end. /* FOR FIRST is_mstr */
   end. /* ELSE DO */
 
   /* FOR RTS RETURN LINES, ZERO REPLENISHMENT SHOULD SHOW IN MRP */
   if pod_rma_type = "O"
      and available is_mstr
      and not is_nettable
      then
      openqty = 0.
 
   /* MRP WORK FILE AND PART MASTER MRP FLAG */
   /* Changed pre-processor to Term */
   /* FOR LOGISTICS ACCOUNTING GIT RECEIPT DO NOT UPDATE mrp_det RECORDS */
   if not lagit then do:
      {us/mf/mfmrw.i "pod_det" pod_part pod_nbr string(pod_line) """"
         ? pod_due_date openqty "SUPPLY" PURCHASE_ORDER pod_site}
   end.
 
end.
else do:
 
   /* FOR LOGISTICS ACCOUNTING GIT RECEIPT DO NOT CREATE ORD-PO */
   if pod_status = "x" and not lagit then do:
      /* Create a tr_hist ORD-PO to reduce tr_qty_req by cancel qty */
      {us/mf/mfpotr.i "QTYCHG" "RECEIPT"}
 
   end.
end.
